;
define(function() {
	/**
	 * URL工具箱
	 */
	var MOURLTookit = function() {
		return new MOURLTookit.init();
	};

	MOURLTookit.init = function() {};

	var pt = MOURLTookit.prototype;

	MOURLTookit.init.prototype = pt;
	
	/**
	 * URL 转对象
	 * @param {String} url url
	 */
	pt.urlToObj = function(url) {
		var regex = /(\w+)=([^&#]*)/igm;
		var matchStr = null;
		var obj = {};
		while((matchStr = regex.exec(url)) != null) {
			obj[matchStr[1]] = matchStr[2];
		}
		return obj;
	}
	
	/**
	 * 对象转URL
	 * @param {Object} baseUrl 目标URL
	 * @param {Object} obj 对象
	 */
	pt.objToUrl = function(baseUrl, obj) {
		var parameters = "";
		var url = "";
		for(var key in obj) {
			parameters += key + "=" + obj[key] + "&";
		}
		parameters = parameters.replace(/&$/, "");
		if(/\?$/.test(baseUrl)) {
			url = baseUrl + parameters;
		} else {
			url = baseUrl.replace(/\/?$/, '?') + parameters;
		}
		return url;
	}
	
	/**
	 * 获得URL中的查询参数
	 * @param {Object} url
	 */
	pt.parseQueryString = function(url) {
		var obj = {};
		if(url) {
			url = url.replace(/#[^#]*$/, "");
			var index = url.indexOf("?");
			if(index != -1) {
				var queryStr = url.substr(index + 1);
				var marchResult = null;
				var regex = /(\w+)(=([^&#]+)?)?/g;
				while((marchResult = regex.exec(queryStr)) != null) {
					if(marchResult[1] in obj) {
						var values = obj[marchResult[1]];
						if(values instanceof Array) {
							values.push(marchResult[2] ? (marchResult[3] ? marchResult[3] : "") : null);
							obj[marchResult[1]] = values;
						} else {
							var arr = [];
							arr.push(values);
							arr.push(marchResult[2] ? (marchResult[3] ? marchResult[3] : "") : null);
							obj[marchResult[1]] = arr;
						}
					} else {
						obj[marchResult[1]] = marchResult[2] ? (marchResult[3] ? marchResult[3] : "") : null;
					}
				}
			}
		}
		return obj;
	}

	mofum.extend(MOURLTookit, Object);
	return MOURLTookit;
});